package com.higold.cloud.mvp.presenter

import com.higold.cloud.base.BasePresenter
import com.higold.cloud.mvp.contract.RegionalContract
import com.higold.cloud.mvp.model.RegionalModel
import com.higold.cloud.net.exception.ExceptionHandle

/**
 *    author : lxz
 *    date   : 2019/9/2 15:49
 *    desc   :
 */
class RegionalPresenter : BasePresenter<RegionalContract.View>(), RegionalContract.Presenter {

    private val achieveModel by lazy { RegionalModel() }

    override fun requestRegionalList() {
        checkViewAttached()
        mRootView?.showLoading()
        val disposable = achieveModel.requestRegionalList()
                .subscribe({ regionalList ->
                    mRootView?.setRegionalList(regionalList)
                }, { throwable ->
                    //处理异常
                    mRootView?.showError(ExceptionHandle.handleException(throwable), ExceptionHandle.errorCode)
                })
        addSubscription(disposable)
    }
}